package com.cleaningcloud.cld.mapper.mini;

import com.cleaningcloud.cld.domain.mini.UserInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

public interface MiniPersonnelMapper {

    /**
     * 根据员工id获取员工属性
     *
     * @param staffId
     * @return
     */
    UserInfo selectStaffAttributesByStaffId(Long staffId);

    /**
     * 待办事项
     *
     * @param staffId
     * @return
     */
    Map<String, Object> getStaffTodo(@Param("projectPostId") Long projectPostId, @Param("staffId") Long staffId);


    /**
     * 查询补卡代办
     *
     * @return
     */
    int getReplaceTodo(@Param("projectPostId") Long projectPostId, @Param("isAdmin") Long isAdmin);


    /**
     * 查询工作计划代办
     *
     * @return
     */
    int getWorkPlanTodo(@Param("postId") Long postId);

    /**
     * @Author Shaw
     * @Description 主管未处理客诉
     * @date: 2025-06-19 14:02
     * @param: //TODO
     */
    @Select("SELECT count( 1 ) FROM cld_complaints c  WHERE  ((c.handle_status = 0 ) or (c.handle_status = 1 and c.assign_staff_id = #{staffId})) and c.project_id = #{projectId}")
    int getComplaintAdminTodo(@Param("projectId") Long projectId, @Param("staffId") Long staffId);

    /**
     * @Author Shaw
     * @Description 领班/员工未处理客诉
     * @date: 2025-06-19 14:02
     * @param: //TODO
     */
    @Select("SELECT count( 1 ) FROM cld_complaints c  WHERE c.handle_status = 1 and c.assign_staff_id = #{staffId} and c.project_id = #{projectId}")
    int getComplaintTodo(@Param("projectId") Long projectId, @Param("staffId") Long staffId);

    /**
     * @Author Shaw
     * @Description 主管未处理工作安排
     * @date: 2025-06-19 14:02
     * @param: //TODO
     */
    @Select("SELECT count( 1 ) FROM cld_temporary c  " +
            "WHERE  ((c.handle_status = 0 and c.project_id = #{projectId}) or ((c.handle_status = 1 and FIND_IN_SET(#{staffId},c.handle_staff_id) > 0 and c.project_id = #{projectId} " +
            "and (select if_status from cld_temporary_reply tr where tr.temporary_id = c.temporary_id and tr.reply_staff_id = #{staffId} order by reply_time desc LIMIT 1) in (0,2))))")
    int getTemporaryAdminTodo(@Param("projectId") Long projectId, @Param("staffId") Long staffId);

    /**
     * @Author Shaw
     * @Description 领班/员工未处理工作安排
     * @date: 2025-06-19 14:02
     * @param: //TODO
     */
    @Select("SELECT count( 1 ) FROM cld_temporary c  " +
            "WHERE  c.handle_status = 1 and FIND_IN_SET(#{staffId},c.handle_staff_id) > 0 and c.project_id = #{projectId} " +
            "and (select if_status from cld_temporary_reply tr where tr.temporary_id = c.temporary_id and tr.reply_staff_id = #{staffId} order by reply_time desc LIMIT 1) in (0,2)")
    int getTemporaryTodo(@Param("projectId") Long projectId, @Param("staffId") Long staffId);

}
